package org.aplikator.client.shared.descriptor;

import org.aplikator.client.local.widgets.HasFields;
import org.aplikator.client.local.widgets.ReferenceFieldWidget;

import com.google.gwt.user.client.ui.Widget;
import org.jboss.errai.common.client.api.annotations.Portable;

@SuppressWarnings("serial")
//@Portable
public class ReferenceFieldDTO extends WidgetPropertyDTOBase implements RenderWidgetAware, ContainsViewDTOReference {

	public static final String TYPE_KEY = "reference";
	
    private ViewDTO view;
    private WidgetDTO child;

	private boolean selfReferenceFlag;
    
    //private boolean 
    
    @SuppressWarnings("unused")
    public ReferenceFieldDTO() {//TODO custom marshaller
    }

    public ReferenceFieldDTO(PropertyDTO property, ViewDTO view, WidgetDTO child) {
        super(property);
        this.view = view;
        this.child = child;
    }

    public ViewDTO getView() {
		return view;
	}
    
    public void setView(ViewDTO view) {
		this.view = view;
	}
    
    public WidgetDTO getChild() {
		return child;
	}
    
    public void setChild(WidgetDTO child) {
		this.child = child;
	}
    
    
    
    @Override
	public boolean isSelfReferenceFlag() {
		return this.selfReferenceFlag;
	}

	@Override
	public void setSelfReferenceFlag(boolean sref) {
		this.selfReferenceFlag = sref;
	}

	@Override
    public Widget getWidget(HasFields form) {
        ReferenceFieldWidget field = new ReferenceFieldWidget(property.getLocalizedName(), view, ((RenderWidgetAware)child).getWidget(form));
        field.setEnabled(isEnabled());
        field.setProperty(property);
        form.registerDataField(field);
        return field;
    }

}
